def p(n):
    for d in range(2, n):
        if n % d == 0:
            return False
    return True


n = int(input())
r = 0
if 1000 <= n <= 9999:
    n = str(n)
    a1 = int(n[0])
    a2 = int(n[1])
    a3 = int(n[2])
    a4 = int(n[3])
    a5 = int(n[0:2])
    a6 = int(n[1:3])
    a7 = int(n[2:4])
    a8 = int(n[0:3])
    a9 = int(n[1:4])
    a10 = int(n)
    a = [a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]
    a.sort(reverse=True)
    for x in a:
        if p(x):
            r = x
            break
print(r)
